home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_rmannotes.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-07-23  |  2.2 KB  |  79 lines

  1. /* rmannotes.sl
  2.  * 
  3.  * macros to be used in conjunction with shaders described in
  4.  * the RManNotes web pages. 
  5.  *   http://www.cgrg.ohio-state.edu/~smay/RManNotes
  6.  *
  7.  */
  8.  
  9. #define pulse(a,b,fuzz,x) (smoothstep((a)-(fuzz),(a),(x)) - \
  10.                smoothstep((b)-(fuzz),(b),(x)))
  11.  
  12. #define boxstep(a,b,x)    clamp(((x) - (a))/((b) - (a)), 0, 1)
  13.  
  14. #define repeat(x,freq)    (mod((x) * (freq), 1.0))
  15.  
  16. #define odd(x)            (mod((x), 2) == 1)
  17. #define even(x)           (mod((x), 2) == 0)
  18.  
  19. #define whichtile(x,freq) (floor((x) * (freq)))
  20.  
  21. /* rotate2d()
  22.  *
  23.  * 2D rotation of point (x,y) about origin (ox,oy) by an angle rad.
  24.  * The resulting point is (rx, ry).
  25.  *
  26.  */
  27. #define rotate2d(x,y,rad,ox,oy,rx,ry) \
  28.   rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox); \
  29.   ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy)
  30.  
  31. /* topolar2d()
  32.  * 
  33.  * 2D cartesian -> polar coordinates
  34.  * converts the point (x,y) to radius 'r' and angle 'theta' (in radians).
  35.  * theta will be in the range [-PI,PI].
  36.  *
  37.  */
  38. #define topolar2d(x, y, r, theta) \
  39.   r = sqrt((x) * (x) + (y) * (y)); \
  40.   theta = atan(y, x) 
  41.  
  42. /* boolean ops (from Perlin85)
  43.  *
  44.  */
  45. #define intersection(a,b) ((a) * (b))
  46. #define union(a,b)        ((a) + (b) - (a) * (b))
  47. #define difference(a,b)   ((a) - (a) * (b))
  48. #define complement(a)     (1 - (a))
  49.  
  50.  
  51. /* blend() and lerp() are equivalent. blend() is used as a substitute for
  52.  * mix because it allows non-scalar 3rd arguments.
  53.  *
  54.  */
  55. #define blend(a,b,x) ((a) * (1 - (x)) + (b) * (x))
  56. #define lerp(a,b,x)  ((a) * (1 - (x)) + (b) * (x))
  57.  
  58. /* signed noise
  59.  *
  60.  */
  61. #define snoise(x)    (noise(x) * 2 - 1)
  62. #define snoise2(x,y) (noise(x,y) * 2 - 1)
  63.  
  64. /* uniformly distributed noise
  65.  *
  66.  */
  67. #define udn(x,lo,hi) (smoothstep(.25, .75, noise(x)) * ((hi) - (lo)) + (lo))
  68. #define udn2(x,y,lo,hi) (smoothstep(.25, .75, noise(x,y)) * ((hi)-(lo))+(lo))
  69.  
  70. /* sample rate metrics (from Apodaca92)
  71.  *
  72.  */
  73. #define MINFILTERWIDTH  1e-7
  74. #define MINDERIV        0.0003    /* sqrt(MINFILTERWIDTH) */
  75.  
  76. #define filterwidth(x) (max(abs(Du(x) * (du)) + (Dv(x) * (dv)),MINFILTERWIDTH))
  77. #define filterwidth_point(p) (max(sqrt(area(p)), MINFILTERWIDTH))
  78.  
  79.